package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsBrand;
import com.qf.service.DtsAdminBrandService;
import com.qf.service.DtsAdminService;
import com.qf.service.DtsCategoryService;
import com.qf.util.ResponseUtil;
import com.qf.vo.CatVo;
import com.qf.vo.DtsBrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/brand")
public class DtsAdminBrandController {

    @Autowired
    DtsAdminBrandService adminBrandService;
    @Autowired
    DtsAdminService adminService;
    @Autowired
    DtsCategoryService categoryService;

    @RequestMapping("/delete")
    public Object delete(@RequestBody DtsBrand dtsBrand){

        return adminBrandService.delete(dtsBrand);
    }

    @RequestMapping("/update")
    public Object update(@RequestBody DtsBrand dtsBrand){
        DtsBrand dtsBrand1 = adminBrandService.update(dtsBrand);
        return ResponseUtil.ok(dtsBrand1);
    }

    @RequestMapping("/create")
    public Object create(@RequestBody DtsBrand dtsBrand){
        DtsBrand dtsBrand1 = adminBrandService.insert(dtsBrand);

        return ResponseUtil.ok(dtsBrand1);
    }

    @GetMapping("/catAndAdmin")
    public Object catAndAdmin(){
        List<Map<String,Object>> adminList = adminService.queryAdminList();
        List<CatVo> catVos = categoryService.queryCategoryList();
        Map<String,Object> data = new HashMap<>();
        data.put("adminList",adminList);
        data.put("categoryList",catVos);
        return ResponseUtil.ok(data);
    }

    @GetMapping("/list")
    public Object list(
            @RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
            @RequestParam(value = "limit",required = false,defaultValue = "10") Integer limit,
            String sort, String order, Integer id, String name){

        IPage<DtsBrandVo> iPage = adminBrandService.queryPage(page,limit,sort,order,id,name);

        Map<String,Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }
}
